import { Component } from 'react'
import Taro from '@tarojs/taro'
import { Image, Button, View, ScrollView, Input } from '@tarojs/components'
import { connect } from 'react-redux'
import { LoadStudentActionAsync,DeleteStudentActionAsync,AddStudentActionAsync} from '../../redux/action/studentAction';
import { ChangeLoadingAction } from '../../redux/action/loadingAction';
import Loading from '../../components/Loading/index'
import dev from '../../../config/dev';
import './index.less'

const isH5 = process.env.TARO_ENV === 'h5'

@connect(	state => ({
    studentList:state.studentList
	}),
	{LoadStudentActionAsync,DeleteStudentActionAsync,AddStudentActionAsync,ChangeLoadingAction}
)
class Index extends Component {
  state={
    // list:[1,2,3,4,5,6,7,8],
    // chooseIndex:2,
    // flag:false
  }

  // UNSAFE_componentWillMount () { console.log('UNSAFE_componentWillMount,组件还没挂载前');if(isH5){console.log('你当前环境为H5')} }

  // componentDidMount () { console.log('componentDidMount,组件挂载后');}

  // shouldComponentUpdate (nextProps,nextState) { console.log('shouldComponentUpdate,组件是否需要更新',nextProps,nextState);return true }

  // componentWillUnmount () { console.log('componentWillUnmount,组件卸载前') }

  // componentDidShow () { console.log('componentDidShow,组件显示后') }

  // componentDidHide () { console.log('componentDidHide,组件隐藏后') }

    // onLoad
  onLoad (options) {
    // scene 需要使用 decodeURIComponent 才能获取到生成二维码时传入的 scene
    // const scene = decodeURIComponent(options.scene)
    // console.log(scene)
  }

  // onReady
  onReady () {}

  // 对应 onShow
  componentDidShow () {}

  // 对应 onHide
  componentDidHide () {}

  // 对应 onPullDownRefresh，除了 componentDidShow/componentDidHide 之外，
  // 所有页面生命周期函数名都与小程序相对应
  onPullDownRefresh () {}

  getQrCode(){
    Taro.showLoading({
      title:'生成中...'
    })
    let that=this
    Taro.cloud.callFunction({
      // name:'createQRCode',
      // name:'wxacode',
      name:'getUnlimited',
      data:{
        "page": 'pages/index/index',
        "scene": 'a=1',
        "checkPath": true,
        "envVersion": 'release'
      },
      success(res){
        console.log(res)
        let fileManager=Taro.getFileSystemManager();
        let filePath = Taro.env.USER_DATA_PATH+'/qr.jpg'
        fileManager.writeFile({
          filePath:filePath,
          encoding:'binary',
          data:res.result.buffer,
          success(res){
            console.log(filePath)
            that.setState({src:filePath})
            Taro.hideLoading({})
          }
        })
      },
    })
  }
  render () {
    return (
      <View style={{height:'100vh',padding:'0 40rpx',display:'flex',justifyContent:'center',alignItems:'center'}}>
        <Loading></Loading>
        <Image
          style={{width:'100vw',height:'100vh',position:'absolute',top:'0',left:'0',zIndex:'-1'}}
          src={dev.baseUrl+'/files/bgindex.jpg'}
        />
        <View style={{display:'flex',
        flexDirection:'column',
        justifyContent:'center',
        alignItems:'center',
        position:'relative',
        border:'1rpx #fff solid',
        color:'#fff',
        padding:'100rpx 0',
        borderRadius:'20rpx',
        width:'100%'
      }}
        >
          <View style={{fontSize:'35rpx'}}>欢迎来到</View>
          <View style={{marginTop:'20rpx',fontSize:'40rpx'}}>南客餐饮店</View>
          <View style={{marginTop:'20rpx',fontSize:'35rpx'}}>请扫码点餐</View>
        </View>
      </View>
    )
  }
}
Index.defaultProps = {}
export default Index

